/**
* Validate data
* @create date: 21/12/2013
* @author: haipt
* 
*/
function validate(id,idError,message)
{
    this.id = id;
    this.idError = idError;
    this.valueInput = document.getElementById(id).value;
    this.errorHtmlObj = document.getElementById(idError);
    this.message = message;  
    
}
validate.prototype.setMessage = function(message)
{
    this.message = message;
}
validate.prototype.setId = function(id)
{
    this.id = id; 
    this.valueInput = document.getElementById(id).value;  
}
validate.prototype.setIdError = function (idError)
{
    this.idError = idError;
}
validate.prototype.notEmpty = function () 
{
    var result =false;
    if(this.valueInput=="")
    {
        this.errorHtmlObj.innerHTML=this.message;
        result = false
    }
    else{
        this.errorHtmlObj.innerHTML="";
        result = true;
    }
    return result;
   
}
validate.prototype.email = function()
{
    var regMail    = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/;
	var checkFlg   = true ;
    if(!regMail.test(this.valueInput))
	{
		this.errorHtmlObj.innerHTML=this.message;
        checkFlg = false;
	}
    else{
        this.errorHtmlObj.innerHTML="";
        checkFlg = true;
    }
    return checkFlg; 
}
validate.prototype.isNumber = function()
{
    var checkFlg = false;
    if (!this.valueInput.match(/^\d+$/) && this.valueInput != "" )
	{
		this.errorHtmlObj.innerHTML=this.message;
        checkFlg = false;
	}
	else
	{
		this.errorHtmlObj.innerHTML="";
        checkFlg = true;
	}
    return checkFlg;
}
validate.prototype.date = function()
{
    var pattern  = /^\d{2}\-\d{2}\-\d{4}$/;
    var checkFlg = false;
    
    if(!this.valueInput.match(pattern) && this.valueInput != "")
    {
       this.errorHtmlObj.innerHTML=this.message;
       checkFlg = false;
    }
    else{
        this.errorHtmlObj.innerHTML="";
        checkFlg = true;
    }
    return checkFlg;
}
validate.prototype.min = function(number)
{
    var checkFlg = false;
    if(this.valueInput != "" && this.valueInput.length <number)
    {
        this.errorHtmlObj.innerHTML=this.message;
        checkFlg = false;
    }
    else{
        this.errorHtmlObj.innerHTML="";
        checkFlg = true;
    }
    return checkFlg;
}
validate.prototype.max = function(number)
{
    var checkFlg = false;
    if(this.valueInput != "" && this.valueInput.length > number)
    {
        this.errorHtmlObj.innerHTML=this.message;
        checkFlg = false;
    }
    else{
        this.errorHtmlObj.innerHTML="";
        checkFlg = true;
    }
    return checkFlg;
}
validate.prototype.minToMax = function(min,max)
{
    var checkFlg = false;
    if(this.valueInput != "" && (this.valueInput.length > max || this.valueInput.length < min))
    {
        this.errorHtmlObj.innerHTML=this.message;
        checkFlg = false;
    }
    else{
        this.errorHtmlObj.innerHTML="";
        checkFlg = true;
    }
    return checkFlg;
}
 